<script setup lang="ts">

// 声明外部传入的数据
const props = defineProps({
  dictType: {type: String, default: ''},
  dictValue: {type: String, default: ''},
  placeholder: {type: String, default: '请选择'}
});
// 定义需要回传的数据
const emits = defineEmits(["update:dictValue"]);

// 定义字典的数据列表
let dataList: any;
const {proxy} = getCurrentInstance() as ComponentInternalInstance
dataList = toRefs<any>(proxy?.useDict(props.dictType))[props.dictType];

const dictData = computed({
  get() {
    return props.dictValue
  },
  set(val) {
    emits("update:dictValue", val)
  }
})

</script>

<template>
  <el-select v-model="dictData" :placeholder="props.placeholder" clearable>
    <el-option v-for="item in dataList" :key="item.value" :label="item.name" :value="item.value" />
  </el-select>
</template>
